import request from './request'
import { useUserStore } from '../store/modules/user'
import { AxiosPromise } from 'axios'

// 获取部门列表
export function getnetworkList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getList',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 获取所有部门下拉数据
 * @param {Object} data - 请求参数
 * @param {Number} data.limit - 一页显示多少条
 * @param {String} data.name - 搜索关键字
 * @param {Number} data.page - 当前页码
 */
export function getNetworkPageSelect(
  data: NetworkAPIRequest.GetOptionsList,
): AxiosPromise<NetworkAPIResponse.OptionsList> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/getNetworkPageSelect',
    method: 'post',
    headers: token,
    data,
  })
}

// 根据部门ID获取部门详情
export function getnetworkDetail(id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getDetail/' + id,
    method: 'get',
    headers: token,
  })
}
// 批量启用或禁用部门
export function setDisable(data, status) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/disable',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}
// 批量删除部门
export function setDelete(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/delete',
    method: 'DELETE',
    headers: token,
    data,
  })
}
// 新增或修改部门
export function addNetwork(data: NetworkAPIRequest.NetworkSave): AxiosPromise<APIResponse> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/save',
    method: 'post',
    headers: token,
    data,
  })
}

// 分页获取部门类型下拉数据
export function networkTypePageSelect(data: { limit: number; name: string; page: number }) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/networkTypePageSelect',
    method: 'post',
    headers: token,
    data,
  })
}

// 获取部门详情之工单明细列表
export function getNetworkDetailOrderList(data, networkId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailOrderList/' + networkId,
    method: 'post',
    headers: token,
    data,
  })
}
// 获取部门详情之部门人员列表
export function getNetworkDetailEmpList(data, networkId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailEmpList/' + networkId,
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 获取部门详情之部门人员列表的详情
 * @param {string} empRelationId 部门人员关联ID
 * @param {string} id 服务人员ID
 * @returns {Promise<any>}
 */
export function getNetworkDetailEmpListDetail(empRelationId: string, id: string) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/getNetworkDetailEmpListDetail/${id}`,
    method: 'get',
    headers: token,
    params: { empRelationId },
  })
}

// 新增或修改部门人员
export function empSave(data: NetworkAPIRequest.NetworkPersonAddOrUpdate) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/save',
    method: 'post',
    headers: token,
    data,
  })
}

// 根据服务人员关联ID删除部门人员
export function deleteNetworkEmp(empRelationId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/deleteNetworkEmp/' + empRelationId,
    method: 'DELETE',
    headers: token,
  })
}
//  获取部门人员下拉数据
export function getNetworkEmpPageSelect(
  data: { limit: number; page: number; name: string },
  networkId: string,
): AxiosPromise<NetworkAPIResponse.PersonOptionList> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/getNetworkEmpPageSelect/' + networkId,
    method: 'post',
    headers: token,
    data,
  })
}

//获取部门字段列表
export function getnetworkSerList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/getList',
    method: 'post',
    headers: token,
    data,
  })
}

//新增或修改部门自定义字段
export function saveNetworkField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/save',
    method: 'post',
    headers: token,
    data,
  })
}

//批量启用或禁用部门字段
export function batchDisableNetworkField(data, status) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/disable',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}

//批量删除部门字段
export function deleteNetworkField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/delete',
    method: 'delete',
    headers: token,
    data,
  })
}

// 获取部门字段详情
export function getServiceInfo(id: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/network/field/getDetail/' + id,
    method: 'post',
  })
}

// 获取部门人员字段详情
export function getNetworkEmpFieldDetail(id: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/network/emp/field/getDetail/' + id,
    method: 'post',
  })
}

//新增或修改部门人员自定义字段
export function saveNetworkEmpField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/field/save',
    method: 'post',
    headers: token,
    data,
  })
}

//获取部门人员字段列表
export function getNetworkEmpList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/field/getList',
    method: 'post',
    headers: token,
    data,
  })
}

//批量启用或禁用部门人员字段
export function batchUpdateNetworkEmpFieldStatus(data, status) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/field/disable',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}

//批量删除部门字段
export function delNetworkEmpField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/field/delete',
    method: 'delete',
    headers: token,
    data,
  })
}
//   获取修改部门前的信息
export function getBeforeNetworkEditSelect(
  networkId: string,
): AxiosPromise<NetworkAPIResponse.BeforeEdit> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getBeforeNetworkEditSelect/' + networkId,
    method: 'get',
    headers: token,
  })
}
// 获取部门字段下拉数据
export function networkFieldSelect() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/networkFieldSelect',
    method: 'get',
    headers: token,
  })
}

// 服务人员列表接口
export function getEmpList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/getList',
    method: 'POST',
    headers: token,
    data,
  })
}

//获取部门详情之工单物料列表
export function getNetworkDetailOrderSpareList(data, id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailOrderSpareList/' + id,
    method: 'post',
    headers: token,
    data,
  })
}
//获取部门详情之工单费用列表
export function getNetworkDetailOrderFeeList(data, id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailOrderFeeList/' + id,
    method: 'post',
    headers: token,
    data,
  })
}
//获取部门详情之部门结算
export function getNetworkDetailModuleSettlementList(data, id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailModuleSettlementList/' + id,
    method: 'post',
    headers: token,
    data,
  })
}
//获取部门详情之资质认证信息
export function getNetworkDetailAuthenField(id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/getNetworkDetailAuthenField/' + id,
    method: 'get',
    headers: token,
  })
}
//获取认证字段列表
export function getNetworkfieldcList(data, type) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/authen/field/getList/' + type,
    method: 'post',
    headers: token,
    data,
  })
}
//批量删除认证字段
export function getNetworkDelete(data, type) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/authen/field/delete/' + type,
    method: 'delete',
    headers: token,
    data,
  })
}
//批量启用或禁用认证字段
export function getNetworkDisable(data, status, type) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/authen/field/disable/' + type,
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}
//根据认证字段ID获取认证字段详情
export function getNetworkDetail(id, type) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/authen/field/getDetail/${type}/${id}`,
    method: 'get',
    headers: token,
  })
}
//保存或更新认证字段
export function getNetworkfieldcSave(data, type) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/authen/field/save/' + type,
    method: 'post',
    headers: token,
    data,
  })
}

//获取人员等级列表
export function getNetworkLevelList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/level/getList',
    method: 'post',
    headers: token,
    data,
  })
}
//根据人员等级ID批量删除
export function getNetworkLevelDelete(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/level/delete',
    method: 'delete',
    headers: token,
    data,
  })
}
//批量启用或禁用人员等级
export function getNetworkLevelDisable(data, status) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/level/disable',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}
//新增或更新人员等级
export function getNetworkLevelDetail(id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/emp/level/getDetail/${id}`,
    method: 'get',
    headers: token,
  })
}
//新增或更新人员等级
export function getNetworkfieldcLevelSave(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/level/save',
    method: 'post',
    headers: token,
    data,
  })
}

//获取人员技能列表
export function getNetworkSkillList(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/skill/getList',
    method: 'post',
    headers: token,
    data,
  })
}
//删除技能
export function getNetworkSkillDelete(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/skill/delete',
    method: 'delete',
    headers: token,
    data,
  })
}
//批量启用或禁用技能
export function getNetworkSkillDisable(data, status) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/skill/disable',
    method: 'post',
    headers: token,
    data,
    params: { status },
  })
}
//根据技能ID获取技能详情
export function getNetworkSkillDetail(id) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/emp/skill/getDetail/${id}`,
    method: 'get',
    headers: token,
  })
}
//新增或更新部门人员技能
export function getNetworkfieldcSkillSave(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/emp/skill/save',
    method: 'post',
    headers: token,
    data,
  })
}
// 获取部门人员字段下拉数据
export function networkEmpFieldSelect(): AxiosPromise<NetworkAPIResponse.DetailEmpCustomField> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/networkEmpFieldSelect',
    method: 'get',
    headers: token,
  })
}
// 获取部门人员等级下拉数据
export function getNetworkEmpLevelSelect(data: { name: string; limit: number; page: number }) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/getNetworkEmpLevelSelect',
    method: 'post',
    headers: token,
    data,
  })
}
// 获取部门人员技能下拉数据
export function getNetworkEmpSkillSelect(data: { name: string; limit: number; page: number }) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/getNetworkEmpSkillSelect',
    method: 'post',
    headers: token,
    data,
  })
}
// 获取所有部门导出字段
export function getNetworkExportFields() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/export/getNetworkExportFields',
    method: 'get',
    headers: token,
  })
}
// 获取部门初始化系统导出字段
export function getNetworkSysInitExportField() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/export/getNetworkSysInitExportField',
    method: 'get',
    headers: token,
  })
}
// 获取部门自定义字段
export function getNetworkCustomField() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/export/getNetworkCustomField',
    method: 'get',
    headers: token,
  })
}
// 保存并导出部门字段
export function saveAndExportNetworkField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/export/saveAndExportNetworkField',
    method: 'post',
    headers: token,
    data,
    responseType: 'blob',
  })
}
// 保存部门导出字段
export function saveExportNetworkField(data) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/network/field/export/save',
    method: 'post',
    headers: token,
    data,
  })
}

// 根据部门分类或区域查询对应的部门
interface NetworkOptional {
  area: string
  city: string
  limit: number
  name: string
  page: number
  province: string
  type: number
  typeId: string | number
}
export function getNetworkSelect(data: NetworkOptional) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/networkSelect/getNetworkSelect',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 批量更新部门接单策略
 * @param {boolean} autoSureReceiveOrder 是否自动接单：false-手动确认，true-自动接单
 * @param {Array<string>} data 部门ID
 */
export function updateAutoSureReceiveOrder(
  autoSureReceiveOrder: boolean,
  data: Array<string>,
): AxiosPromise<APIResponse> {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/strategy/updateAutoSureReceiveOrder?autoSureReceiveOrder=${autoSureReceiveOrder}`,
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 批量更新部门审核取消工单策略
 * @param {boolean} autoCheckCancelOrder 是否自动审核取消工单：false-手动审核，true-自动审核
 * @param {Array<string>} data 部门ID
 */
export const updateAutoCheckCancelOrder = (
  autoCheckCancelOrder: boolean,
  data: Array<string>,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/strategy/updateAutoCheckCancelOrder?autoCheckCancelOrder=${autoCheckCancelOrder}`,
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 批量更新部门审核结单策略
 * @param {boolean} autoCheckEndOrder 是否自动审核结单：false-手动审核，true-自动审核
 * @param {Array<string>} data 部门ID
 */
export const updateAutoCheckEndOrder = (
  autoCheckEndOrder: boolean,
  data: Array<string>,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/network/strategy/updateAutoCheckEndOrder?autoCheckEndOrder=${autoCheckEndOrder}`,
    method: 'post',
    data,
  })
}

/**
 * 批量更新允许更改备件价格
 * @param {boolean} enableUpdateSparePrice 是否允许更改备件价格：false-关闭，true-允许修改
 * @param {Array<string>} data 部门ID
 */
export const enableUpdateSparePrice = (
  enableUpdateSparePrice: boolean,
  data: Array<string>,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/strategy/enableUpdateSparePrice?enableUpdateSparePrice=${enableUpdateSparePrice}`,
    method: 'post',
    headers: token,
    data,
  })
}
/**
 * 批量更改部门团队模式
 */
export const updateNetworkTeamType = (data, teamType) => {
  return request({
    url: `/network/updateNetworkTeamType?teamType=${teamType}`,
    method: 'post',
    data,
  })
}
/**
 * 获取部门机构列表
 */
export const agencygetList = (data) => {
  return request({
    url: `/network/agency/getList`,
    method: 'post',
    data,
  })
}
// 新增或修改部门机构类型
export const agencygetSave = (data) => {
  return request({
    url: `/network/agency/save`,
    method: 'post',
    data,
  })
}
//批量删除部门机构
export const agencygetDelete = (data) => {
  return request({
    url: `/network/agency/delete`,
    method: 'DELETE',
    data,
  })
}
//批量启用或禁用技能
export function agencyNetworkDisable(data, status) {
  return request({
    url: '/network/agency/disable',
    method: 'put',
    data,
    params: { status },
  })
}
// 获取部门机构下拉数据
export const getNetworkAgencyList = (data) => {
  return request({
    url: `/networkSelect/getNetworkAgencyList`,
    method: 'post',
    data,
  })
}
/**批量更改部门关联部门机构*/
export const updateNetworkAgency = (data) => {
  return request({
    url: `/network/updateNetworkAgency`,
    method: 'post',
    data,
  })
}
/**批量更改部门关联的部门分类 */

export const updateNetworkType = (data) => {
  return request({
    url: `/network/updateNetworkType`,
    method: 'post',
    data,
  })
}

/**
 * 批量更新防伪查询策略
 * @param {Boolean} allowAntiFakeQuery 允许防伪查询：false-不允许，true-允许
 * @param {Array<string>} networkIds - 部门id集合
 */
export const updateAntiFakeQueryStrategy = (
  allowAntiFakeQuery: boolean,
  networkIds: Array<string>,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/strategy/updateSecurityCheck?allowSecurityCheck=${allowAntiFakeQuery}`,
    method: 'post',
    headers: token,
    data: networkIds,
  })
}

/**
 * 批量更新是否允许创建工单策略
 * @param {Boolean} allowCreateOrder - 是否允许创建工单
 * @param {Array<string>} networkIds - 部门id集合
 */
export const updateCreateOrderStrategy = (
  allowCreateOrder: boolean,
  networkIds: Array<string>,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/strategy/updateCreateOrder?allowCreateOrder=${allowCreateOrder}`,
    method: 'post',
    headers: token,
    data: networkIds,
  })
}

/**
 * 批量更新物料申请策略
 * @param {Boolean} allowSpareApply - 是否允许申请物料
 * @param {Array<string>} networkIds - 部门id集合
 */
export const updateSpareApplyStrategy = (
  allowSpareApply: boolean,
  networkIds: Array<string>,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/strategy/updateAllowApplySpare?allowApplySpare=${allowSpareApply}`,
    method: 'post',
    headers: token,
    data: networkIds,
  })
}

/**
 * 批量更新知识库查看策略
 * @param {Boolean} allowViewKnow - 是否允许查看知识库
 * @param {Array<string>} networkIds - 部门id集合
 */
export const updateViewKnowStrategy = (
  allowViewKnow: boolean,
  networkIds: Array<string>,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/strategy/updateAllowSelectKnowledgeBase?allowSelectKnowledgeBase=${allowViewKnow}`,
    method: 'post',
    headers: token,
    data: networkIds,
  })
}

/**
 * 根据手机号获取部门人员账号信息
 * @param {String} phone - 部门人员手机号
 * @param {string} networkId - 部门id
 */
export const getNetworkAccountInfoByPhone = (
  phone: string,
  networkId: string,
): AxiosPromise<NetworkAPIResponse.AccountInfoByPhone> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/emp/getNetworkAccountInfo/${phone}`,
    method: 'get',
    headers: token,
    params: { networkId },
  })
}

/**
 * 获取部门策略
 * @param {string} networkId - 部门id
 */
export const getStrategyById = (
  networkId: string,
): AxiosPromise<NetworkAPIResponse.StrategyDetail> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/network/getNetworkStrategy/${networkId}`,
    method: 'get',
    headers: token,
  })
}

/**
 * 获取部门财务信息
 * @param {string} networkId - 部门id
 */
export const getFinancialInfoById = (
  networkId: string,
): AxiosPromise<NetworkAPIResponse.FinancialDetail> => {
  return request({
    url: `/network/getNetworkFinance/${networkId}`,
    method: 'get',
  })
}
/**
 * 获取部门策略
 * @param {string} networkId - 部门id
 */
export const updateallowUpdateSnCode = (allowUpdateSnCode: boolean, networkId: Array<string>) => {
  return request({
    url: `/network/strategy/updateallowUpdateSnCode?allowUpdateSnCode=${allowUpdateSnCode}`,
    method: 'post',
    data: networkId,
  })
}
/**
 *获取部门序列号流水号
 */
export const getNetworkCode = () => {
  return request({
    url: `/sys/serial/number/getNetworkCode`,
    method: 'get',
  })
}

/**
 * 根据手机号查询工程师是否已存在于任意一个部门中
 * @param {String} phone - 工程师手机号
 */
export const isEmpJoinNetwork = (
  phone: string,
): AxiosPromise<APIResponse<{ engineerJoinNetwork: boolean }>> => {
  return request({
    url: `/network/emp/isNetworkEmpJoinNetwork/${phone}`,
    method: 'get',
  })
}

/**
 * 获取登录的账号所在的部门id
 */
export const getLoginAccountNetworkId = (): AxiosPromise<APIResponse<string>> => {
  return request({
    url: '/system/login/getSiteId',
    method: 'get',
  })
}

/**
 * 根据仓库id获取部门信息
 * @param {string} id - 仓库id
 */
export const getNetworkInfoByWarehouseId = (
  id: string,
): AxiosPromise<NetworkAPIResponse.InfoByWarehouseId> => {
  return request({
    url: `/store/transfer/getNetworkkByStore/${id}`,
    method: 'get',
  })
}
